package com.android.lovepick;

import java.lang.ref.WeakReference;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

public class UserInfoActivity extends Activity
{
	private static final int MOD_SUCCESS = 0;
	private final String USERINFO_TAG = "UserInfoAcitivy";
	private String username;
	private TextView txvUserName;
	private Intent intent = null;

	@Override
	public void onCreate(Bundle bundle)
	{
		super.onCreate(bundle);
		setContentView(R.layout.user_info);
		findViews();

		username = this.getIntent().getStringExtra("username");
		Log.i(USERINFO_TAG, "username: " + username);
		txvUserName.setText(username);

	}

	private void findViews()
	{
		txvUserName = (TextView) this.findViewById(R.id.txv_user_name);
	}

	/**
	 * 发布路线按钮, 用户需要选择发布者身份(司机或乘客)才能发布路线
	 * 
	 * @param view
	 */
	public void doLaunchRoute(View view)
	{

		CharSequence[] items = { "作为乘客", "作为司机" };

		AlertDialog.Builder builder = new AlertDialog.Builder(
				UserInfoActivity.this);
		builder.setTitle("请选择发布者身份").setItems(items,
				new DialogInterface.OnClickListener()
				{

					public void onClick(DialogInterface dialog, int which)
					{
						intent = new Intent(getApplicationContext(),
								OrderActivity.class);
						// TODO Auto-generated method stub
						switch (which)
						{
							case 0:
								intent.putExtra("iDriver", 0);
								break;

							case 1:
								intent.putExtra("iDriver", 1);
								break;

							default:
								break;
						}
						startActivity(intent);

					}
				});
		builder.create().show();
	}

	/**
	 * 修改用户信息按钮
	 * 
	 * @param view
	 */
	public void doModUserInfo(View view)
	{
		Intent intent = new Intent(view.getContext(), null);
		startActivityForResult(intent, MOD_SUCCESS);
	}

	/**
	 * 查看所有路线按钮
	 * 
	 * @param view
	 */
	public void doAllRoutes(View view)
	{
		Intent intent = new Intent(view.getContext(), MyOrderActivity.class);
		startActivity(intent);
	}

	public static class UserInfoHandler extends Handler
	{
		private final String USERINFO_HANDLER_TAG = "UserInfoHandler";
		private WeakReference<UserInfoActivity> mReference = null;

		public UserInfoHandler(UserInfoActivity activity)
		{
			mReference = new WeakReference<UserInfoActivity>(activity);
		}

		@Override
		public void handleMessage(Message msg)
		{
			switch (msg.what)
			{
				case 0:

					break;

				default:
					break;
			}
		}
	}

}
